export class DataControl
{
    private static instance = null;
    public static getInstance() : DataControl
    {
        if(null == this.instance){
            this.instance = new DataControl();
        }
        return this.instance;
    }

    public DataBase : object = {
        //苹果
        "b_apple":{ "score": 10, "cost": 5 },
        "apple":{ "score": 30, "cost": 15 },
        "l_apple":{ "score": 60, "cost": 30 },
        //香蕉
        "b_banana":{ "score": 10, "cost": 5 },
        "banana":{ "score": 30, "cost": 15 },
        "l_banana":{ "score": 60, "cost": 30 },
        //葡萄
        "b_grape":{ "score": 10, "cost": 5 },
        "grape":{ "score": 30, "cost": 15 },
        "l_grape":{ "score": 60, "cost": 30 },
        //杨桃
        "b_yangtao":{ "score": 10, "cost": 5 },
        "yangtao":{ "score": 30, "cost": 15 },
        "l_yangtao":{ "score": 60, "cost": 30 }, 
        //草莓
        "b_strawberry":{ "score": 10, "cost": 5 },
        "strawberry":{ "score": 30, "cost": 15 },
        "l_strawberry":{ "score": 60, "cost": 30 },
    }
    public ConfigData  : string[] = [
        "b_strawberry","grape","l_strawberry",
        "grape","b_banana","b_apple",
        "b_apple","l_apple","b_apple",
        "yangtao","banana","l_grape",
        "b_strawberry","l_yangtao","b_strawberry",
        "banana","b_apple","grape",
        "b_apple","yangtao","b_strawberry",
        "b_banana","b_apple","grape"
    ]

    //自己拥有的分数
    private _self_score : number = 0;
    public set SelfScore (score : number) {
        this._self_score = score;
    }
    public get SelfScore() : number {
        return this._self_score;
    }

    //每次消耗的总分
    private _cost_sum : number = 0;
    public set CostSum (cost_score : number) {
        this._cost_sum = cost_score;
    }
    public get CostSum () {
        return this._cost_sum;
    }
    //去重数组
    dedupe (arr: Array<unknown>) : Array<unknown> {
        let new_arr = Array.from(new Set(arr));
        return new_arr;
    }
    //ConfigData去重
    dedupeConfigData(): Array<unknown> {
        return this.dedupe(this.ConfigData);
    }
    //判断消耗分数是否超过拥有的分数
    judgeConstAndScore() : boolean {
        return this.CostSum > this.SelfScore;
    }
}